package com.shxc.smarttrade.dialogactivity;

import android.view.View;

import com.shxc.smarttrade.R;
import com.shxc.smarttrade.base.NoActionBarBaseActivity;
import com.shxc.smarttrade.currency.model.CurrencyModel;
import com.shxc.smarttrade.info.Contents;
import com.shxc.smarttrade.utils.analysis.JsonAnalysisModel;
import com.shxc.smarttrade.utils.analysis.JsonAnalysisUtils;
import com.shxc.smarttrade.utils.ToastUtils;

import org.xchris.view.annotation.ContentView;
import org.xchris.view.annotation.Event;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

/**
 * 昆仑 开户成功
 */
@ContentView(R.layout.activity_dialog_changeacc_kvb)
public class TigerAccDialogActivity extends NoActionBarBaseActivity {

    @Event({R.id.close_imageview, R.id.change_view})
    private void onClick(View view) {
        switch (view.getId()) {
            case R.id.close_imageview:
                finish();
                break;
            case R.id.change_view:
                //切换
                checkType();
                break;
        }
    }

    protected void overridePendingTransitionEnter() {
        overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
    }

    //账户切换
    private void checkType() {
        loadingDialog.show();
        Map<String, Object> map = new HashMap<>();
        map.put("userId", spImp.getUserId());
        map.put("accType", 1);

        com.shxc.smarttrade.utils.MyOkHttpUtils.getServiceDatas(map, Contents.ACCOUNT_CHECKTYPE, new com.shxc.smarttrade.utils.MyOkHttpUtils.ServiceStatus() {
            @Override
            public void success(String response, int d) {
                if (response != null) {
                    JsonAnalysisModel jam = JsonAnalysisUtils.jsonAnalysis(response, CurrencyModel.class);
                    if (jam.isSuccess()) {
                        spImp.setAccType(1);
                        finish();
                    } else {
                        ToastUtils.showToast(jam.getMsg());
                    }
                }
                loadingDialog.dismiss();
            }
            @Override
            public void faild(Call call, Exception e, int id) {
                loadingDialog.dismiss();
            }
        });
    }
}
